<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>Dubbo</title>
    <script type="text/javascript" src="jquery-easyui-1.4.5/jquery.min.js"></script>
    <script type="text/javascript" src="jquery-easyui-1.4.5/jquery.easyui.min.js"></script>
    <link rel="stylesheet" type="text/css" href="css/public.css">
    <script src="js/function/sosowx.js?v=0.2"></script>
    <script type="text/javascript">
        var modelId;
        var detailedId;

        /**
         * 初始模板
         */
        function init() {
            modelId = GetQueryString("id");
            $.ajax({
                type: "GET",
                url: "/metadataQuery/getDetailedList/" + modelId,
                async: true,
                dataType: 'json',
                timeout: 5000,
                contentType: 'application/text;charset=UTF-8',
                success: function (data) {
                    $("#detailedList").html("");
                    for (i = 0; i < data.length; i++) {
                        var li = "<li><a href=\"#\" onclick=\"initdColumnList(" + data[i].detailed_id + ")\">" + data[i].detailed_name + "#" + data[i].source_id + " </a></li>";
                        $("#detailedList").append(li);
                    }
                }
            });
            getFilterList();
        }


        /**
         * 初始化明细表字段
         */
        function initdColumnList(id) {
            detailedId = id;
            getDColumn();
        }

        /**
         * 获取明细表字段
         */
        function getDColumn() {
            $.ajax({
                type: "GET",
                url: "/metadataQuery/getDColumnList/" + detailedId,
                async: true,
                dataType: 'json',
                timeout: 5000,
                contentType: 'application/text;charset=UTF-8',
                success: function (data) {
                    $("#dColumn").html("<thead> <td>数据源字段ID</td> <td>显示名称</td> <td>默认值</td> </thead>");
                    for (i = 0; i < data.length; i++) {
                        var table = "<tr>";
                        table += "<td>" + data[i].column_id + "</td>"
                                + "<td>" + data[i].detailed_show_name + "</td>"
                                + "<td>" + data[i].detailed_default + "</td>";
                        table += "</tr>";
                        $("#dColumn").append(table);
                    }
                }
            });
        }

        /**
         * 获取过滤条件
         */
        function getFilterList() {
            $.ajax({
                type: "GET",
                url: "/metadataQuery/getFilterList/" + modelId,
                async: true,
                dataType: 'json',
                timeout: 5000,
                contentType: 'application/text;charset=UTF-8',
                success: function (data) {
                    $("#filterList").html(" <thead> <td>显示名称</td> <td>数据源字段主键</td> <td>默认值</td> <td>是否模糊查询</td> <td>是否范围查询</td> <td>数据类型</td> </thead>");
                    for (i = 0; i < data.length; i++) {
                        var table = "<tr>";
                        table += "<td>" + data[i].filter_show_name + "</td>"
                                + "<td>" + data[i].column_id + "</td>"
                                + "<td>" + data[i].filter_default_value + "</td>"
                                + "<td>" + data[i].filter_fuzzy + "</td>"
                                + "<td>" + data[i].filter_range + "</td>"
                                + "<td>" + data[i].filter_type + "</td>";
                        table += "</tr>";
                        $("#filterList").append(table);
                    }
                }
            });
        }

        /**
         * 保存明细表
         */
        function saveDetailed() {
            var datas = {
                source_id: $("#sId").val(),
                detailed_name: $("#dName").val(),
                model_id: modelId,
            }
            $.ajax({
                type: "POST",
                url: "/metadataNew/insert/"+Table.META_DETAILED,
                async: true,
                dataType: 'json',
                data: JSON.stringify(datas),
                timeout: 5000,
                contentType: 'application/text;charset=UTF-8',
                success: function (data) {
                    init();
                }
            });
        }

        /**
         * 保存明细表字段
         */
        function saveDColumn() {

            var datas = {
                column_id: $("#columnId").val(),
                detailed_show_name: $("#dsName").val(),
                detailed_default: $("#dcDefault").val(),
                detailed_id: detailedId
            }
            $.ajax({
                type: "POST",
                url: "/metadataNew/insert/"+Table.META_DETAILED_COLUMN,
                async: true,
                dataType: 'json',
                data: JSON.stringify(datas),
                timeout: 5000,
                contentType: 'application/text;charset=UTF-8',
                success: function (data) {
                    getDColumn();
                }
            });
        }

        /**
         * 保存过滤条件
         */
        function saveFilter() {
            var datas = {
                filter_show_name: $("#fsName").val(),
                filter_default_value: $("#fDefault").val(),
                filter_fuzzy: $("#fuzzy").val(),
                filter_range: $("#range").val(),
                column_id: $("#fColumn").val(),
                filter_type: $("#fType").val(),
                model_id: modelId,
            }
            $.ajax({
                type: "POST",
                url: "/metadataNew/insert/"+Table.META_FILTER,
                async: true,
                dataType: 'json',
                data: JSON.stringify(datas),
                timeout: 5000,
                contentType: 'application/text;charset=UTF-8',
                success: function (data) {
                    getFilterList();
                }
            });
        }

    </script>
</head>
<body onload="init();">
<div style="width: auto; float: left">
    <h6>明细表列表</h6>
    数据源主键：<input type="text" id="sId">

    <p/>
    明细表名称：<input type="text" id="dName"><input type="button" value="新增明细表" onclick="saveDetailed()">

    <p/>
    <ul id="detailedList">
    </ul>
</div>
<div style="width: auto; float: left">
    <h6>明细表字段维护</h6>
    数据源字段ID：<input type="text" id="columnId">显示名称：<input type="text" id="dsName">默认值：<input type="text" id="dcDefault">

    <p/>
    <input type="button" value="新增明细表字段" onclick="saveDColumn()">

    <p/>
    <table id="dColumn">
        <thead>
        <td>数据源字段ID</td>
        <td>显示名称</td>
        <td>默认值</td>
        </thead>
    </table>
    <h6>模板过滤条件维护</h6>

    <p/>
    显示名：<input type="text" id="fsName">数据源字段ID：<input type="text" id="fColumn">默认值：<input type="text" id="fDefault">

    <p/>
    是否模糊查询：<select id="fuzzy">
    <option value="0">否</option>
    <option value="1">是</option>
</select>
    是否范围查询：<select id="range">
    <option value="0">否</option>
    <option value="1">是</option>
</select>
    数据类型：<input type="text" id="fType">

    <p/>
    <input type="button" value="新增主表字段" onclick="saveFilter()">

    <p/>
    <table id="filterList">
        <thead>
        <td>显示名称</td>
        <td>数据源字段主键</td>
        <td>默认值</td>
        <td>是否模糊查询</td>
        <td>是否范围查询</td>
        <td>数据类型</td>
        </thead>
    </table>
</div>
</body>
</html>